package chap03.ObjectSort;

/**
 * Created by root on 2017/7/12.
 */
public class ArrayInOb {
    private Person[] a;
    private int nElems;

    public ArrayInOb(int max)         // constructor
    {
        a = new Person[max];               // create the array
        nElems = 0;                        // no items yet
    }

    public void insert(String last, String first, int age)
    {
        a[nElems] = new Person(last, first, age);
        nElems++;                          // increment size
    }

    public void display(){
        for (int j=0; j<nElems; j++ ) {
            a[j].displayPerson();
        }
        System.out.println();
    }

    public void insertionSort(){
        int out, in, min;
        Person temp;
        for (out=1; out<nElems; out++) {
            in = out;
            temp = a[out];
            while (in >0 && (a[in-1].getLast().compareTo(temp.getLast())>0)) {
                a[in] = a[in-1];
                in--;
            }
            a[in] = temp;
        }
    }
}
